package com.neuronbit.businessflow.flow.source;

import com.neuronbit.businessflow.flow.source.util.SourceContext;
import com.neuronbit.businessflow.intellij.model.Node;
import com.neuronbit.businessflow.runtime.EndStep;
import com.neuronbit.businessflow.runtime.StepType;
import com.neuronbit.javaparser.ast.stmt.BlockStmt;

import static java.lang.String.format;


/**
 * The type End step java source.
 */
public class EndStepJavaSource extends StepJavaSource {


    /**
     * Instantiates a new End step java source.
     *
     * @param node          the node
     * @param sourceContext the source context
     */
    public EndStepJavaSource(Node node, SourceContext sourceContext) {
        super(node, sourceContext);
    }

    @Override
    protected void addExtendedType() {
        getStepClass().addExtendedType(format("com.neuronbit.businessflow.runtime.EndStep<%s>", getContextSource().getSimpleName()));
    }

    @Override
    protected StepType getStepType() {
        return StepType.END;
    }

    @Override
    protected void writeStepCallStmt(BlockStmt stepCallStmt) {

    }

    @Override
    protected void afterStepCallStmt(BlockStmt stepCallStmt, BlockStmt methodBody) {
        methodBody.addStatement("this.end(context, flow);");
    }
}
